<?
include_once("../../config.php");
?>


<?//正式开始操作
//

function curl_api($url,$method,$headers,$bodys){
// 创建连接
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); //表示不检查证书
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //信任任何证书
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); //设置直接采用ipv3 防止走ipv6流程，会变慢


// 发送请求
$response = curl_exec($curl);
curl_close($curl);

// 读取响应  result返回所有任务
$result = json_decode($response,true);

return $result;
}





//==============================
//获取一下所有的项目
//==============================
$url    = "https://open.teambition.com/api/project/query";
$method = 'POST';


// 配置headers
$headers = array(
    'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfYXBwSWQiOiI2MDRjODMyN2E1NmUxNjc4Nzk2ZDVmODYiLCJpYXQiOiIxNjY4MjI2OTI3IiwiZXhwIjo0MDk4MTQwNTI3fQ.EUBJTgPGm1wbacNuiCU4rhs1Oz3jdu3QUE6SFF0dRAQ',
    'X-Tenant-Id:5c2f6791e944bc0001767ce8',
    'X-Tenant-Type:organization',
    'Content-Type:application/json'

);

//    BODY内容的设置，获取企业信息，没有用到。
//array的写法会有转义，符号转换不正确，接口会提示错误的。要用=》方法去写。
//$bodys = array(
//    '"pageSize": 100',
//    '"pageSize2": 200'
//);


$bodys = ["pageSize" => 500];
$api_project=curl_api($url,$method,$headers,$bodys);



for($i=0;$i<=count($api_project['result']);$i++)
{
    if(
        (!$api_project['result'][$i]['isSuspended']) &&
        ($api_project['result'][$i]['projectId']!="54f41a3d9a49c2844edb6633") &&  //这是项目模板
        ($api_project['result'][$i]['projectId']!="532a5f27030989e80ae34278") && //这是圆点的
        ($api_project['result'][$i]['projectId']!="6370e94b647cfd3f1e311371") //这是无底深潭
       )
    {
    $project[$i]['name']=$api_project['result'][$i]['name'];
    $project[$i]['projectid']=$api_project['result'][$i]['projectId'];
    }

}


echo  $del_str="delete from ".$table_Prefix."teambition_project where 1=1";
$query = mysql_query($del_str) ;


$p['table']=$table_Prefix."teambition_project";
$p['items']=array("name","projectid");
$p['values']=$project;


echo $insert_sql=insert_datas($p);
$query = mysql_query($insert_sql) ;
mysql_close($con);


?>





